/*
 * @Descripttion:
 * @Version: 1.0
 * @Author: undead
 * @Date: 2022-01-12 15:19:14
 * @LastEditors: undead
 * @LastEditTime: 2022-01-13 10:20:38
 */
const fs = require("fs");
const { resolve } = require("path");

class utils {
  readFileSync(path) {
    if (path.indexOf(":") === -1) {
      path = resolve("./", path);
    }

    return fs.readFileSync(path, {
      encoding: "utf-8",
    });
  }
  saveFileSync(path, content) {
    fs.writeFileSync(path, content, {
      encoding: "utf-8",
    });
  }
  readdirSync(path, suffix) {
    if (path.indexOf(":") === -1) {
      path = resolve("./", path);
    }
    let readDir = fs.readdirSync(path);
    return readDir
      .filter((x) => x.split(".").at(-1) === suffix)
      .map((x) => path + "/" + x);
  }
}
Array.prototype.at = function (index) {
    if (index < 0) return this[this.length - Math.abs(index)];
    return this[index];
};
module.exports = new utils();
